
package com.hlkj.pay.app.merchant.ext.impl.leshua;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.extension.annotation.Extension;
import com.hlkj.pay.app.merchant.ext.ChannelMerchantAccessExtPt;
import com.hlkj.pay.app.merchant.ext.MerchantExtConstant;
import com.hlkj.pay.app.merchant.ext.dto.access.*;
import com.hlkj.pay.app.merchant.ext.impl.leshua.constant.LeshuaPayConstant;
import com.hlkj.pay.app.merchant.ext.impl.leshua.constant.XmlUtils;
import com.hlkj.pay.app.merchant.ext.impl.leshua.dto.LeshuaPayConfig;
import com.hlkj.pay.app.merchant.ext.impl.leshua.dto.resp.*;
import com.hlkj.pay.app.merchant.ext.impl.leshua.handler.LeshuaPayCommonParamsHandle;
import com.hlkj.pay.app.merchant.ext.impl.yeepay.dto.YeePayAppChannelParams;
import com.hlkj.pay.app.merchant.impl.MerchantAccessStatusProcessHandler;
import com.hlkj.pay.dto.merchant.*;
import com.hlkj.pay.dto.pay.PayCommonAppDto;
import com.hlkj.pay.enums.MerchantEnum;
import com.hlkj.pay.enums.PayEnums;
import com.hlkj.pay.infrastructure.model.merchant.MerchantAccessAuthDO;
import com.hlkj.pay.infrastructure.model.merchant.MerchantAccessInfoDO;
import com.hlkj.pay.infrastructure.model.pay.PayChannelRequestDO;
import com.hlkj.pay.infrastructure.model.pay.ProviderChannelConfigDO;
import com.hlkj.pay.service.merchant.IMerchantAccessService;
import com.hlkj.pay.vo.order.resp.MerchantProductQueryResp;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.utils.StringPool;

/**
 * 乐刷进件操作
 */
@Slf4j
@Repository
@RequiredArgsConstructor
@Extension(bizId = MerchantExtConstant.CHANNEL_LESHUA_PAY)
public class LeshuaPayMerchantAccessExtPt implements ChannelMerchantAccessExtPt {

    private final LeshuaPayCommonParamsHandle leshuaPayCommonParamsHandle;

    private final MerchantAccessStatusProcessHandler merchantAccessStatusProcessHandler;

    private final IMerchantAccessService merchantAccessService;

    @Value("${hlkj.domain}")
    private String domain;

    @Override
    public void channelConfigCheck(ChannelMerchantAccessCommonContext channelMerchantAccessCommonContext) {

    }

    @Override
    public void merchantAccess(ChannelMerchantAccessContext channelMerchantAccessContext) {
        log.info("乐刷渠道提交进件 请求参数:{}", JsonUtils.toJsonString(channelMerchantAccessContext));
        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantAccessContext.getProviderChannelConfig(),
                channelMerchantAccessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessContext.setProcessStatus(false);
            return;
        }
        MerchantAccessDto merchantAccessDto = channelMerchantAccessContext.getMerchantAccessDto();
        MerchantAccessInfoDO merchantAccessInfo = merchantAccessDto.getMerchantAccessInfo();
        // 初始化乐刷配置
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        // 企业类型
        MerchantEnum.MERCHANT_TYPE merchantType = MerchantEnum.MERCHANT_TYPE.from(merchantAccessInfo.getType());

        PayChannelRequestDO payChannelRequestDO = new PayChannelRequestDO();
        channelMerchantAccessContext.setPayChannelRequestDO(payChannelRequestDO);

        try {
            // 请求参数
            Map<String,Object> data = new HashMap<>();
            // 商户基本信息
            Map<String,Object> merchantSubjectInfo = new HashMap<>();
            merchantSubjectInfo.put("merchantShortName",merchantAccessDto.getMerchantAccessBusiness().getShortName());

            if(merchantType == MerchantEnum.MERCHANT_TYPE.COMPANY){
                merchantSubjectInfo.put("merchantName",merchantAccessDto.getMerchantAccessLicense().getName());
                merchantSubjectInfo.put("merchantType",leshuaPayCommonParamsHandle.companyType(Integer.valueOf(merchantAccessDto.getMerchantAccessLicense().getCompanyType()),merchantType));
            }else{
                merchantSubjectInfo.put("merchantName",merchantAccessDto.getMerchantAccessLegal().getName());
                merchantSubjectInfo.put("merchantType","1");
            }

            merchantSubjectInfo.put("mccCode",merchantAccessDto.getMerchantAccessBusiness().getMcc());
            data.put("baseInfo",merchantSubjectInfo);

            // 商户法人信息
            Map<String,Object> merchantCorporationInfo = new HashMap<>();
            merchantCorporationInfo.put("legalName",merchantAccessDto.getMerchantAccessLegal().getName());
            merchantCorporationInfo.put("credentialType",leshuaPayCommonParamsHandle.certType(merchantAccessDto.getMerchantAccessLegal().getCertType()));
            merchantCorporationInfo.put("idCardNo",merchantAccessDto.getMerchantAccessLegal().getCertNo());
            merchantCorporationInfo.put("idcardFrontPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("idcardFrontPic",merchantAccessDto.getMerchantAccessLegal().getCertFrontUrl(),leshuaPayConfig));
            merchantCorporationInfo.put("idcardBackPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("idcardBackPic",merchantAccessDto.getMerchantAccessLegal().getCertBackUrl(),leshuaPayConfig));
            merchantCorporationInfo.put("idCardStart",merchantAccessDto.getMerchantAccessLegal().getCertBeginDate());
            if(merchantAccessDto.getMerchantAccessLegal().getCertValidityType() == 1){
                merchantCorporationInfo.put("idCardEnd","长期");
            }else{
                merchantCorporationInfo.put("idCardEnd",merchantAccessDto.getMerchantAccessLegal().getCertEndDate());
            }
            data.put("legalPerson",merchantCorporationInfo);

            // 商户联系人信息
            Map<String,Object> merchantContactInfo = new HashMap<>();
            // 联系人非同法
            if(merchantAccessDto.getMerchantAccessInfo().getContactType() != null && merchantAccessDto.getMerchantAccessInfo().getContactType() == 0){
                merchantContactInfo.put("name",merchantAccessDto.getMerchantAccessLegal().getName());
                merchantContactInfo.put("idCardNo",merchantAccessDto.getMerchantAccessLegal().getCertNo());
                merchantContactInfo.put("mobile",merchantAccessDto.getMerchantAccessLegal().getPhone());
            }else{
                merchantContactInfo.put("name",merchantAccessDto.getMerchantAccessContact().getName());
                merchantContactInfo.put("idCardNo",merchantAccessDto.getMerchantAccessContact().getCertNo());
                merchantContactInfo.put("mobile",merchantAccessDto.getMerchantAccessContact().getPhone());
            }
            data.put("contactInfo",merchantContactInfo);

            // 企业需要填营业执照信息
            if(merchantType == MerchantEnum.MERCHANT_TYPE.COMPANY){
                Map<String,Object> merchantLisenceInfo = new HashMap<>();
                merchantLisenceInfo.put("license",merchantAccessDto.getMerchantAccessLicense().getLicenseCode());
                merchantLisenceInfo.put("licenseType",leshuaPayCommonParamsHandle.licenseType(merchantAccessDto.getMerchantAccessLicense().getLicenseType()));
                merchantLisenceInfo.put("licenseFullName",merchantAccessDto.getMerchantAccessLicense().getName());
                merchantLisenceInfo.put("licenseAddress",merchantAccessDto.getMerchantAccessLicense().getAddress());
                merchantLisenceInfo.put("licensePic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("licensePic",merchantAccessDto.getMerchantAccessLicense().getLicenseUrl(),leshuaPayConfig));
                merchantLisenceInfo.put("licenseStart",merchantAccessDto.getMerchantAccessLicense().getLicenseBeginDate());
                if(merchantAccessDto.getMerchantAccessLicense().getLicenseValidityType() == 1){
                    merchantLisenceInfo.put("licenseEnd","长期");
                }else{
                    merchantLisenceInfo.put("licenseEnd",merchantAccessDto.getMerchantAccessLicense().getLicenseEndDate());
                }
                data.put("licenseInfo",merchantLisenceInfo);
            }

            // 经营地址
            Map<String,Object> businessAddressInfo = new HashMap<>();
            businessAddressInfo.put("provinceCode",merchantAccessDto.getMerchantAccessBusiness().getProvinceCode());
            businessAddressInfo.put("cityCode",merchantAccessDto.getMerchantAccessBusiness().getCityCode());
            businessAddressInfo.put("areaCode",merchantAccessDto.getMerchantAccessBusiness().getAreaCode());

            businessAddressInfo.put("address",merchantAccessDto.getMerchantAccessBusiness().getAddress());
            data.put("addressInfo",businessAddressInfo);

            // 结算信息
            Map<String,Object> settlementAccountInfo = new HashMap<>();
            switch (MerchantEnum.CARD_TYPE.from(merchantAccessDto.getMerchantAccessCard().getType())){
                // 法人结算
                case CORPORATE_ACCOUNT:
                    settlementAccountInfo.put("type",2);
                    settlementAccountInfo.put("legalFlag",1);
                    settlementAccountInfo.put("bankCardFrontPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("bankCardFrontPic",merchantAccessDto.getMerchantAccessCard().getLicenseUrl(),leshuaPayConfig));
                    break;
                // 对私法人结算
                case PRIVATE_CORPORATE_ACCOUNT:
                    settlementAccountInfo.put("type",1);
                    settlementAccountInfo.put("legalFlag",1);
                    settlementAccountInfo.put("idCardNo",merchantAccessDto.getMerchantAccessLegal().getCertNo());
                    settlementAccountInfo.put("idCardType",1);
                    settlementAccountInfo.put("mobile",merchantAccessDto.getMerchantAccessCard().getCardPhone());
                    settlementAccountInfo.put("bankCardFrontPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("bankCardFrontPic",merchantAccessDto.getMerchantAccessCard().getSettleCardFrontUrl(),leshuaPayConfig));
                    break;
                // 对私非法人结算
                case PRIVATE_NON_CORPORATE_ACCOUNT:
                    settlementAccountInfo.put("type",1);
                    settlementAccountInfo.put("legalFlag",0);
                    settlementAccountInfo.put("idCardNo",merchantAccessDto.getMerchantAccessCard().getCertNo());
                    settlementAccountInfo.put("idCardType",1);
                    settlementAccountInfo.put("mobile",merchantAccessDto.getMerchantAccessCard().getCardPhone());
                    settlementAccountInfo.put("bankCardFrontPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("bankCardFrontPic",merchantAccessDto.getMerchantAccessCard().getSettleCardFrontUrl(),leshuaPayConfig));
                    // 非法人结算必填
                    settlementAccountInfo.put("nonLegSettleAuthPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("nonLegSettleAuthPic",merchantAccessDto.getMerchantAccessCard().getAuthUrl(),leshuaPayConfig));
                    settlementAccountInfo.put("nonLegIdcardFrontPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("nonLegIdcardFrontPic",merchantAccessDto.getMerchantAccessCard().getCertFrontUrl(),leshuaPayConfig));
                    settlementAccountInfo.put("nonLegIdcardBackPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("nonLegIdcardBackPic",merchantAccessDto.getMerchantAccessCard().getCertBackUrl(),leshuaPayConfig));
                    settlementAccountInfo.put("nonLegalPersonCertificateStartDate",merchantAccessDto.getMerchantAccessCard().getCertBeginDate());
                    if(merchantAccessDto.getMerchantAccessCard().getCertValidityType() == 1){
                        settlementAccountInfo.put("nonLegalPersonCertificateEndDate","长期");
                    }else{
                        settlementAccountInfo.put("nonLegalPersonCertificateEndDate",merchantAccessDto.getMerchantAccessCard().getCertEndDate());
                    }
                    break;
            }
            settlementAccountInfo.put("unionpay",merchantAccessDto.getMerchantAccessCard().getBranchCode());
            settlementAccountInfo.put("holder",merchantAccessDto.getMerchantAccessCard().getName());
            settlementAccountInfo.put("bankCardNo",merchantAccessDto.getMerchantAccessCard().getCardNo());
            data.put("accountInfo",settlementAccountInfo);

            // 店铺信息
            Map<String,Object> shopInfo = new HashMap<>();
            shopInfo.put("insidePic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("insidePic",merchantAccessDto.getMerchantAccessBusiness().getStoreIndoorUrl(),leshuaPayConfig));
            shopInfo.put("doorPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("doorPic",merchantAccessDto.getMerchantAccessBusiness().getStoreHeaderUrl(),leshuaPayConfig));
            shopInfo.put("cashierDeskPic",leshuaPayCommonParamsHandle.getUploadMerQualUrl("cashierDeskPic",merchantAccessDto.getMerchantAccessBusiness().getStoreCashierDeskUrl(),leshuaPayConfig));
            data.put("shopInfo",shopInfo);

            // otherInfo
            Map<String,Object> otherInfo = new HashMap<>();
            // 回调通知
            otherInfo.put("notifyAddress",channelMerchantAccessContext.getAsyncReturnUrl());
            if(StrUtil.isNotEmpty(leshuaPayConfig.getReportConfigId())){
                otherInfo.put("reportConfigId",leshuaPayConfig.getReportConfigId());
            }
            data.put("otherInfo",otherInfo);

            // 记录请求参数
            payChannelRequestDO.setRequestId(merchantAccessInfo.getRequestId());
            payChannelRequestDO.setRequestParams(JsonUtils.toJsonString(data));
            payChannelRequestDO.setRequestUrl(LeshuaPayConstant.REGISTER_URL);
            payChannelRequestDO.setRequestTime(System.currentTimeMillis());


            log.info("乐刷"+merchantType.getDesc()+"开户 请求参数 request:{}", JsonUtils.toJsonString(data));
            LeshuaBaseResp response = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.REGISTER_URL,JSONUtil.toJsonStr(data),leshuaPayConfig,merchantAccessInfo.getRequestId());
            log.info("乐刷"+merchantType.getDesc()+"开户 返回参数 response:{}", JsonUtils.toJsonString(response));

            payChannelRequestDO.setResponse(JsonUtils.toJsonString(response));

            if(LeshuaPayConstant.OK.equals(response.getRespCode())){
                // 修改不返回数据
                if(StrUtil.isEmpty(merchantAccessInfo.getSubMchId())){
                    LeshuaAccessResp accessResp = JSONUtil.toBean(response.getData(),LeshuaAccessResp.class);
                    if(StrUtil.isNotEmpty(accessResp.getMerchantId())){
                        merchantAccessInfo.setSubMchId(accessResp.getMerchantId());
                    }
                }
                // 下一步就是查询申请状态
                channelMerchantAccessContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.CHANNEL_APPROVE);
                channelMerchantAccessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.SUBMIT);
            }else{
                channelMerchantAccessContext.setRemark(response.getRespMsg());
                channelMerchantAccessContext.setProcessStatus(Boolean.FALSE);
                channelMerchantAccessContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
            }


        } catch (Exception e) {
            e.printStackTrace();
            log.error("乐刷企业开户请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessContext.setRemark("乐刷企业开户请求失败,失败信息, " + e.getMessage());
            channelMerchantAccessContext.setProcessStatus(Boolean.FALSE);
            channelMerchantAccessContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
        }

    }

    @Override
    public String requestUrl(MerchantAccessDto merchantAccessInfoDO) {
        return null;
    }

    @Override
    public String channelParams(AccessChannelParamsDto accessChannelParamsDto) {
        YeePayAppChannelParams params = new YeePayAppChannelParams();
        params.setSubMchId(accessChannelParamsDto.getSubMchId());
        return JsonUtils.toJsonStringNotNull(params);
    }

    @Override
    public void merchantAccessQuery(ChannelMerchantAccessQueryContext channelMerchantAccessQueryContext) {

        log.info("乐刷进件查询请求参数:{}", JsonUtils.toJsonString(channelMerchantAccessQueryContext));
        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantAccessQueryContext.getProviderChannelConfig(),
                channelMerchantAccessQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessQueryContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessQueryContext.getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        try{
            String merchantId = merchantAccessInfo.getSubMchId();
            if(StrUtil.isEmpty(merchantId)){
                channelMerchantAccessQueryContext.setRemark("乐刷查询进件 merchantId is null");
                channelMerchantAccessQueryContext.setProcessStatus(false);
                return;
            }

            Map<String,Object> data = new HashMap<>();
            data.put("merchantId",merchantId);
            LeshuaBaseResp response = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.AUDIT_QUERY_RUL,JSONUtil.toJsonStr(data),leshuaPayConfig);
            log.info("乐刷查询进件 返回参数:{}", response);

            if(!LeshuaPayConstant.OK.equals(response.getRespCode())){
                channelMerchantAccessQueryContext.setProcessStatus(false);
                channelMerchantAccessQueryContext.setRemark(response.getRespMsg());
                return;
            }
            // 返回参数
            LeshuaAccessAuthResp accessResp = JSONUtil.toBean(response.getData(),LeshuaAccessAuthResp.class);
            /**
             * 审核状态转换
             * 系统审核状态 0：草稿 1：鉴权中 2：已提交，等待平台审核，3：系统自动审核中，4：系统审核通过渠道审核中，5：平台审核中，6：待签约，7：签约中，8：待配置，9：配置中，10：审核完成，11：审核驳回
             * 乐刷进件审核状态如下：
             * REJECTED：审核退回
             * REVIEW：  待人工检查
             * PASSED：  审核通过
             * UNKNOWN： 审核结果未知
             * ADD_INFO：待完善资料
             * AUDITING：待审核
             */
            switch (accessResp.getMerchantStatus()) {
                case "ADD_INFO":
                case "UNKNOWN":
                case "REJECTED":
                    channelMerchantAccessQueryContext.setProcessStatus(false);
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
                    channelMerchantAccessQueryContext.setRemark(accessResp.getRefusalReason());
                    break;
                case "REVIEW":
                case "AUDITING":
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.CHANNEL_APPROVE);
                    channelMerchantAccessQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.CONTINUE_APPLY_QUERY);
                    break;
                case "PASSED":
                    channelMerchantAccessQueryContext.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_SUCCESS);
                    channelMerchantAccessQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.SUBMIT);
                    // 审核成功更新费率信息
                    leshuaPayCommonParamsHandle.updateFeeInfo(merchantAccessInfo,leshuaPayConfig);
                    break;
                default:
                    channelMerchantAccessQueryContext.setProcessStatus(false);
                    channelMerchantAccessQueryContext.setRemark(response.getRespMsg());
                    break;
            }

        }catch (Exception e){
            e.printStackTrace();
            channelMerchantAccessQueryContext.setProcessStatus(false);
            channelMerchantAccessQueryContext.setRemark(e.getMessage());
        }
    }

    @Override
    public void merchantSign(ChannelMerchantAccessSignContext channelMerchantAccessSignContext) {
    }

    @Override
    public void merchantSignQuery(ChannelMerchantAccessSignContext channelMerchantAccessSignContext) {
    }

    @Override
    public void merchantBusinessOpen(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void wechatConfigInit(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        try {
            List<PayCommonAppDto> payCommonAppList = channelMerchantBusinessContext.getPayCommonAppList();
            List<PayCommonAppDto> wechatCommonApp = null;
            if (CollUtil.isNotEmpty(payCommonAppList)) {
                wechatCommonApp = payCommonAppList.stream().filter(payCommonAppDto ->  payCommonAppDto.getPayWayDO() !=null && PayEnums.PAY_TYPE.WECHAT.getCode().equals(payCommonAppDto.getPayWayDO().getType()))
                        .collect(Collectors.toList());
            }
            // 没有微信执行 配置完成
            if (CollectionUtils.isEmpty(wechatCommonApp)) {
                // channelMerchantBusinessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.ALIPAY_AUTH);
                return;
            }
            if (!domain.endsWith(StringPool.SLASH)) {
                domain = domain + StringPool.SLASH;
            }
            // 查询微信商户号
            List<String> mchIds = leshuaPayCommonParamsHandle.getMchId(leshuaPayConfig,merchantAccessInfo.getSubMchId(), PayEnums.PAY_TYPE.WECHAT);
            for(String mchId:mchIds){
                if(StrUtil.isEmpty(mchId)){
                    continue;
                }
                // 更新支付APPID配置
                Map<String,Object> appIdMap = new HashMap<>();
                appIdMap.put("merchantId",merchantAccessInfo.getSubMchId());
                appIdMap.put("wxSubMchId",mchId);
                appIdMap.put("configType",1);
                for(PayCommonAppDto commonAppDto:wechatCommonApp){
                    appIdMap.put("sub_appid",commonAppDto.getAppId());
                    log.info("乐刷 微信参数初始化配置 更新APPID 请求参数 :{}", JsonUtils.toJsonString(appIdMap));
                    LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_CONFIG_URL,JSONUtil.toJsonStr(appIdMap),leshuaPayConfig);
                    log.info("乐刷 微信参数初始化配置 更新APPID 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
                }
                // 支付授权目录配置
                Map<String,Object> jsapiMap = new HashMap<>();
                jsapiMap.put("merchantId",merchantAccessInfo.getSubMchId());
                jsapiMap.put("wxSubMchId", mchId);
                jsapiMap.put("configType", 3);
                jsapiMap.put("jsapi_path", domain);
                log.info("乐刷 微信参数初始化配置 更新支付授权目录 请求参数 :{}", JsonUtils.toJsonString(jsapiMap));
                LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_CONFIG_URL,JSONUtil.toJsonStr(jsapiMap),leshuaPayConfig);
                log.info("乐刷 微信参数初始化配置 更新支付授权目录 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
            }
        }
        catch (Exception e) {
            log.error("乐刷微信配置init请求失败,失败信息 message: {}", e);
            channelMerchantBusinessContext.setRemark("乐刷微信配置init请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }

        channelMerchantBusinessContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.FINISH);
    }


    @Override
    public void wechatConfigAdd(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantBusinessContext.getProviderChannelConfig(),
                channelMerchantBusinessContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantBusinessContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantBusinessContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantBusinessContext.getMerchantAccessDto().getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        // 配置信息
        MerchantWechatConfigDto merchantWechatConfigDto = channelMerchantBusinessContext.getMerchantWechatConfigDto();
        try {
            // 错误消息
            Map<String,String> failMap = new HashMap<>();
            // 查询微信商户号
            List<String> mchIds = leshuaPayCommonParamsHandle.getMchId(leshuaPayConfig,merchantAccessInfo.getSubMchId(), PayEnums.PAY_TYPE.WECHAT);
            for(String mchId:mchIds){
                // 支付appId目录列表
                String appId = merchantWechatConfigDto.getAppId();
                if(StrUtil.isNotEmpty(appId)){
                    Map<String,Object> appIdMap = new HashMap<>();
                    appIdMap.put("merchantId",merchantAccessInfo.getSubMchId());
                    appIdMap.put("wxSubMchId",mchId);
                    appIdMap.put("configType",1);
                    appIdMap.put("sub_appid",appId);
                    log.info("乐刷 微信配置add 更新APPID 请求参数 :{}", JsonUtils.toJsonString(appIdMap));
                    LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_CONFIG_URL,JSONUtil.toJsonStr(appIdMap),leshuaPayConfig);
                    if(!LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
                        failMap.put(appId,leshuaBaseResp.getRespMsg());
                    }
                    log.info("乐刷 微信配置add 更新APPID 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
                }

                // 支付授权目录列表
                String jsAPIPath = merchantWechatConfigDto.getJsAPIPath();
                if(StrUtil.isNotEmpty(jsAPIPath)){
                    Map<String,Object> jsapiMap = new HashMap<>();
                    jsapiMap.put("merchantId",merchantAccessInfo.getSubMchId());
                    jsapiMap.put("wxSubMchId", mchId);
                    jsapiMap.put("configType", 3);
                    jsapiMap.put("jsapi_path", jsAPIPath);
                    log.info("乐刷 微信配置add 更新支付授权目录 请求参数 :{}", JsonUtils.toJsonString(jsapiMap));
                    LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_CONFIG_URL,JSONUtil.toJsonStr(jsapiMap),leshuaPayConfig);
                    if(!LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
                        failMap.put(jsAPIPath,leshuaBaseResp.getRespMsg());
                    }
                    log.info("乐刷 微信配置add 更新支付授权目录 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
                }
            }

            if(MapUtil.isNotEmpty(failMap)){
                channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
                channelMerchantBusinessContext.setRemark(JSONUtil.toJsonPrettyStr(failMap));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("乐刷微信配置add请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantBusinessContext.setRemark("乐刷微信配置add请求失败,失败信息" + e.getMessage());
            channelMerchantBusinessContext.setProcessStatus(Boolean.FALSE);
        }

    }

    @Override
    public void wechatConfigQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {

        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        try {
            MerchantWechatConfigListDto merchantWechatConfigListDto = new MerchantWechatConfigListDto();
            merchantWechatConfigListDto.setAppIdList(CollUtil.newArrayList());
            merchantWechatConfigListDto.setJsApiPath(CollUtil.newArrayList());
            // 查询微信商户号
            List<String> mchIds = leshuaPayCommonParamsHandle.getMchId(leshuaPayConfig,merchantAccessInfo.getSubMchId(), PayEnums.PAY_TYPE.WECHAT);
            Map<String,Object> data = new HashMap<>();
            data.put("merchantId",merchantAccessInfo.getSubMchId());

            for(String mchId:mchIds){
                data.put("wxSubMchId",mchId);
                log.info("乐刷 微信配置查询 请求参数 :{}", JsonUtils.toJsonString(data));
                LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_CONFIG_QRY_URL,JSONUtil.toJsonStr(data),leshuaPayConfig);
                log.info("乐刷 微信配置查询 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
                if(LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
                    LeshuaAccessConfigResp configResp = JSONUtil.toBean(leshuaBaseResp.getData(), LeshuaAccessConfigResp.class);
                    if(configResp != null){
                        if (configResp.getAppid_config_list() != null) {
                            if (CollUtil.isNotEmpty(configResp.getAppid_config_list().getAppid_config_list())) {
                                for (LeshuaAccessConfigResp.AppIdConfig.AppIdConfigDetail appIdConfigDetail :configResp.getAppid_config_list().getAppid_config_list()) {
                                    MerchantWechatConfigAppIdDto merchantWechatConfigAppIdDto = new MerchantWechatConfigAppIdDto();
                                    merchantWechatConfigAppIdDto.setSubAppid(appIdConfigDetail.getSub_appid());
                                    merchantWechatConfigAppIdDto.setSubscribeAppid(appIdConfigDetail.getSubscribe_appid());
                                    merchantWechatConfigListDto.getAppIdList().add(merchantWechatConfigAppIdDto);
                                }
                            }
                        }
                        if (configResp.getJsapi_path_list() != null && CollUtil.isNotEmpty(configResp.getJsapi_path_list().getJsapi_path_list())) {
                            for (String jsapi_path : configResp.getJsapi_path_list().getJsapi_path_list()) {
                                merchantWechatConfigListDto.getJsApiPath().add(jsapi_path);
                            }
                        }
                    }
                }else{
                    log.error("乐刷 微信配置查询 请求失败,失败信息 message: {}", leshuaBaseResp.getRespMsg());
                }
            }
            channelMerchantAccessAuthQueryContext.setMerchantWechatConfigListDto(merchantWechatConfigListDto);
            // 乐刷 微信 不需要报备
            channelMerchantAccessAuthQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.FINISH);
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("乐刷微信配置查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("乐刷微信配置查询请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }
    }

    @Override
    public void wechatAuthConfig(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public boolean authConfigQueryType() {
        return false;
    }

    @Override
    public void wechatAuthQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {

        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        try {

            List<MerchantAccessAuthDO> authDOList = new ArrayList<>();
            // 查询微信商户号
            List<String> mchIds = leshuaPayCommonParamsHandle.getMchId(leshuaPayConfig,merchantAccessInfo.getSubMchId(), PayEnums.PAY_TYPE.WECHAT);
            for(String mchId:mchIds){
                MerchantAccessAuthDO merchantAccessAuthDO = new MerchantAccessAuthDO();
                merchantAccessAuthDO.setType(PayEnums.PAY_TYPE.WECHAT.getCode());
                merchantAccessAuthDO.setSn(merchantAccessInfo.getSn());
                merchantAccessAuthDO.setAccessId(merchantAccessInfo.getId());
                merchantAccessAuthDO.setSubMchId(mchId);
                merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVE.getCode());
                authDOList.add(merchantAccessAuthDO);
                // 异步更新授权状态
                MerchantAuthStatusConfig merchantAuthStatusConfig = new MerchantAuthStatusConfig();
                merchantAuthStatusConfig.setReportMerchantNo(mchId);
                merchantAuthStatusConfig.setAccessId(merchantAccessInfo.getId());
                merchantAuthStatusConfig.setPayType(PayEnums.PAY_TYPE.WECHAT);
                merchantAccessStatusProcessHandler.processAuthAccess(merchantAuthStatusConfig);
            }

            // Map<String,Object> data = new HashMap<>();
            // data.put("merchantId",merchantAccessInfo.getSubMchId());
            // log.info("乐刷 微信认证查询 请求参数 :{}", JsonUtils.toJsonString(data));
            // LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_AUTH_QUERY_RUL,JSONUtil.toJsonStr(data),leshuaPayConfig);
            // log.info("乐刷 微信认证查询 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
            // if(LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
            //     LeshuaAccessWechatAuthResp wechatAuthResp = JSONUtil.toBean(leshuaBaseResp.getData(),LeshuaAccessWechatAuthResp.class);
            //
            //
            //     switch (wechatAuthResp.getApplyStatus()){
            //         case "APPLYMENT_STATE_WAITTING_FOR_AUDIT":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVEING.getCode());
            //             break;
            //         case "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.WAIT_CONFIRM.getCode());
            //             merchantAccessAuthDO.setAuthUrl(wechatAuthResp.getQrcodeData());
            //             break;
            //         case "APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.WAIT_AUTH.getCode());
            //             merchantAccessAuthDO.setAuthUrl(wechatAuthResp.getQrcodeData());
            //             break;
            //         case "APPLYMENT_STATE_PASSED":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVE.getCode());
            //             merchantAccessAuthDO.setAuthUrl(wechatAuthResp.getQrcodeData());
            //             break;
            //         case "APPLYMENT_STATE_REJECTED":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.REJECT.getCode());
            //             break;
            //         case "APPLYMENT_STATE_FREEZED":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.FROZEN.getCode());
            //             merchantAccessAuthDO.setAuthUrl(wechatAuthResp.getQrcodeData());
            //             break;
            //         case "APPLYMENT_STATE_CANCELED":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.CANCEL.getCode());
            //             break;
            //         default:
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.NO_APPLY.getCode());
            //             break;
            //     }

            channelMerchantAccessAuthQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.WECHAT_AUTH);
            channelMerchantAccessAuthQueryContext.setMerchantAccessAuthList(authDOList);
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("乐刷微信认证查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("乐刷微信认证查询请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }

    }

    @Override
    public void alipayAuthConfig(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void alipayAuthQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {

        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        try {

            List<MerchantAccessAuthDO> authDOList = new ArrayList<>();
            // 查询微信商户号
            List<String> mchIds = leshuaPayCommonParamsHandle.getMchId(leshuaPayConfig,merchantAccessInfo.getSubMchId(), PayEnums.PAY_TYPE.ALIPAY);
            for(String mchId:mchIds){
                MerchantAccessAuthDO merchantAccessAuthDO = new MerchantAccessAuthDO();
                merchantAccessAuthDO.setType(PayEnums.PAY_TYPE.ALIPAY.getCode());
                merchantAccessAuthDO.setSn(merchantAccessInfo.getSn());
                merchantAccessAuthDO.setAccessId(merchantAccessInfo.getId());
                merchantAccessAuthDO.setSubMchId(mchId);
                merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVE.getCode());
                authDOList.add(merchantAccessAuthDO);
                // 异步更新授权状态
                MerchantAuthStatusConfig merchantAuthStatusConfig = new MerchantAuthStatusConfig();
                merchantAuthStatusConfig.setReportMerchantNo(mchId);
                merchantAuthStatusConfig.setAccessId(merchantAccessInfo.getId());
                merchantAuthStatusConfig.setPayType(PayEnums.PAY_TYPE.ALIPAY);
                merchantAccessStatusProcessHandler.processAuthAccess(merchantAuthStatusConfig);
            }

            // Map<String,Object> data = new HashMap<>();
            // MerchantAccessAuthDO merchantAccessAuthDO = new MerchantAccessAuthDO();
            // data.put("merchantId",merchantAccessInfo.getSubMchId());
            // log.info("乐刷 支付宝认证查询 请求参数 :{}", JsonUtils.toJsonString(data));
            // LeshuaBaseResp leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.ALI_AUTH_QUERY_RUL,JSONUtil.toJsonStr(data),leshuaPayConfig);
            // log.info("乐刷 支付宝认证查询 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
            // if(LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
            //     LeshuaAccessAliAuthResp aliAuthResp = JSONUtil.toBean(leshuaBaseResp.getData(),LeshuaAccessAliAuthResp.class);
            //
            //     merchantAccessAuthDO.setType(PayEnums.PAY_TYPE.ALIPAY.getCode());
            //     merchantAccessAuthDO.setSn(merchantAccessInfo.getSn());
            //     merchantAccessAuthDO.setAccessId(merchantAccessInfo.getId());
            //     switch (aliAuthResp.getOrderstatus()){
            //         case "AUDITING":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVEING.getCode());
            //             break;
            //         case "CONTACT_CONFIRM":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.WAIT_CONFIRM.getCode());
            //             merchantAccessAuthDO.setAuthUrl(aliAuthResp.getQrCode());
            //             break;
            //         case "LEGAL_CONFIRM":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.WAIT_AUTH.getCode());
            //             merchantAccessAuthDO.setAuthUrl(aliAuthResp.getQrCode());
            //             break;
            //         case "AUDIT_PASS":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.APPROVE.getCode());
            //             merchantAccessAuthDO.setAuthUrl(aliAuthResp.getQrCode());
            //             break;
            //         case "AUDIT_REJECT":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.REJECT.getCode());
            //             break;
            //         case "AUDIT_FREEZE":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.FROZEN.getCode());
            //             merchantAccessAuthDO.setAuthUrl(aliAuthResp.getQrCode());
            //             break;
            //         case "CANCELED":
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.CANCEL.getCode());
            //             break;
            //         default:
            //             merchantAccessAuthDO.setStatus(MerchantEnum.MERCHANT_AUTH_STATUS.NO_APPLY.getCode());
            //             break;
            //     }
            //
            //     // 查询支付宝商户号
            //     String mchId = leshuaPayCommonParamsHandle.getMchId(leshuaPayConfig,merchantAccessInfo.getSubMchId(), PayEnums.PAY_TYPE.ALIPAY);
            //     merchantAccessAuthDO.setMchId(mchId);
            //     merchantAccessAuthDO.setSubMchId(aliAuthResp.getApplymentId());
            //     if(CollUtil.isNotEmpty(aliAuthResp.getVerifyList())){
            //         merchantAccessAuthDO.setRejectReason(aliAuthResp.getVerifyList().get(0).getFailReason());
            //     }
            //
            // }
            channelMerchantAccessAuthQueryContext.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.ALIPAY_AUTH);
            channelMerchantAccessAuthQueryContext.setMerchantAccessAuthList(authDOList);
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("乐刷支付宝认证查询请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("乐刷支付宝认证查询请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }

    }

    @Override
    public MerchantAccessCallBackDto accessCallBackParamsParse(HttpServletRequest request, ProviderChannelConfigDO providerChannelConfigDO) {

        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(providerChannelConfigDO,true);

        MerchantAccessCallBackDto merchantAccessCallBackDto = new MerchantAccessCallBackDto();
        if (yeePayConfigCommonResult.isSuccess()) {
            LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
            try{
                // 获取响应内容
                String response = XmlUtils.getContentFromRequestInputStream(request);
                LeshuaAccessAuthNotify authNotify = JSONUtil.toBean(response,LeshuaAccessAuthNotify.class);
                log.info("乐刷收到回调 response:{}",response);
                switch (authNotify.getAuditInfo().getMerchantStatus()) {
                    case "ADD_INFO":
                    case "UNKNOWN":
                    case "REJECTED":
                        merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_REFUSE);
                        merchantAccessCallBackDto.setRemark(authNotify.getAuditInfo().getRefusalReason());
                        break;
                    case "REVIEW":
                    case "AUDITING":
                        merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.CHANNEL_APPROVE);
                        break;
                    case "PASSED":
                        merchantAccessCallBackDto.setAccessStatus(MerchantEnum.ACCESS_STATUS.APPROVE_SUCCESS);
                        merchantAccessCallBackDto.setAuditStatus(MerchantEnum.CHANNEL_CONFIG_STATUS.SUBMIT);
                        // 审核成功更新费率信息
                        leshuaPayCommonParamsHandle.updateFeeInfo(merchantAccessService.queryBySubMchId(authNotify.getMerchantId()),leshuaPayConfig);
                        break;
                    default:
                        merchantAccessCallBackDto.setProcessStatus(false);
                        merchantAccessCallBackDto.setRemark(authNotify.getAuditInfo().getAuditMsg());
                        break;
                }
                merchantAccessCallBackDto.setSubMchId(authNotify.getMerchantId());

            }catch (Exception e){
                e.printStackTrace();
                merchantAccessCallBackDto.setProcessStatus(false);
                merchantAccessCallBackDto.setRemark("乐刷收到回调 plaintTextWithPrivateKey, 解析失败, msg");
            }
        }
        return merchantAccessCallBackDto;
    }

    @Override
    public CommonResult<String> accessCallbackParse(String callBackBody, List<ProviderChannelConfigDO> channelConfigDOList) {
        return null;
    }

    @Override
    public MerchantBusinessCallBackDto businessCallBackParamsParse(String callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return null;
    }

    @Override
    public boolean verify(String callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return false;
    }

    @Override
    public String callBackResponse(CommonResult commonResult) {
        if (commonResult.isSuccess()) {
            return "SUCCESS";
        }
        else {
            return "FAIL";
        }
    }

    @Override
    public void termAdd(ChannelMerchantTermContext channelMerchantTermContext) {
    }

    @Override
    public void reloadMerchantAuth(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void channelSplit(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void productUpdate(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public Integer queryMerAuthStatus(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {

        Integer authStatus = null;
        LeshuaBaseResp leshuaBaseResp = null;
        CommonResult<LeshuaPayConfig> yeePayConfigCommonResult = leshuaPayCommonParamsHandle.leshuaPayConfig(channelMerchantAccessAuthQueryContext.getProviderChannelConfig(),
                channelMerchantAccessAuthQueryContext.isTest());
        if (!yeePayConfigCommonResult.isSuccess()) {
            channelMerchantAccessAuthQueryContext.setRemark(yeePayConfigCommonResult.getMsg());
            channelMerchantAccessAuthQueryContext.setProcessStatus(false);
            return authStatus;
        }
        // 进件信息
        MerchantAccessInfoDO merchantAccessInfo = channelMerchantAccessAuthQueryContext.getMerchantAccessDto().getMerchantAccessInfo();
        // 乐刷配置信息
        LeshuaPayConfig leshuaPayConfig = yeePayConfigCommonResult.getData();
        // 授权状态查询配置
        MerchantAuthStatusConfig authStatusConfig = channelMerchantAccessAuthQueryContext.getMerchantAuthStatusConfig();
        try {
            // 组装参数
            Map<String,Object> data = new HashMap<>();
            // 支付类型
            switch (authStatusConfig.getPayType()){
                case WECHAT:
                    data.put("wxSubMchId",authStatusConfig.getReportMerchantNo());
                    log.info("乐刷 WECHAT 商户授权状态查询 请求参数 :{}", JsonUtils.toJsonString(data));
                    leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.WX_MER_AUTH_QUERY_RUL,JSONUtil.toJsonStr(data),leshuaPayConfig);
                    log.info("乐刷 WECHAT 商户授权状态查询 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
                    if(LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
                        if(leshuaBaseResp.getData().equals("已授权")){
                            authStatus = 1;
                        }else{
                            authStatus = 0;
                        }
                    }
                    break;
                case ALIPAY:
                    data.put("merchantId",merchantAccessInfo.getSubMchId());
                    log.info("乐刷 ALIPAY 商户授权状态查询 请求参数 :{}", JsonUtils.toJsonString(data));
                    leshuaBaseResp = leshuaPayCommonParamsHandle.requestPostApi(LeshuaPayConstant.ALI_MER_AUTH_QUERY_RUL,JSONUtil.toJsonStr(data),leshuaPayConfig);
                    log.info("乐刷 ALIPAY 商户授权状态查询 返回参数 :{}", JsonUtils.toJsonString(leshuaBaseResp));
                    if(LeshuaPayConstant.OK.equals(leshuaBaseResp.getRespCode())){
                        LeshuaAccessAliMerAuthResp merAuthResp = JSONUtil.toBean(leshuaBaseResp.getData(),LeshuaAccessAliMerAuthResp.class);
                        switch (merAuthResp.getCheckResult()){
                            case "AUTHORIZED":
                                authStatus = 1;
                                break;
                            case "UNAUTHORIZED":
                                authStatus = 0;
                                break;
                            case "CLOSED":
                                authStatus = 2;
                                break;
                        }
                    }
                    break;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            log.error("乐刷商户授权状态请求失败,失败信息 message: {}", e.getMessage());
            channelMerchantAccessAuthQueryContext.setRemark("乐刷商户授权状态请求失败,失败信息" + e.getMessage());
            channelMerchantAccessAuthQueryContext.setProcessStatus(Boolean.FALSE);
        }
        return authStatus;
    }

    @Override
    public MerchantProductQueryResp productQuery(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
        return null;
    }

    @Override
    public MerchantChannelSplitCallBackDto easySplitCallBackParamsParse(HttpServletRequest request, ProviderChannelConfigDO providerChannelConfigDO) {
        return null;
    }


}
